<template>
  <view class="content">
    <view class="status_bar"></view>

    <view class="main">
      <view class="main_top">
        <image
          src="../../static/jiantous.png"
          mode=""
          class="main_top_img"
          @click="handleBack"
        ></image>

        <view class="main_top_text">零钱钱包</view>

        <view class="main_top_right" @click="toTransfer()">转账</view>
      </view>

      <view class="main_price">
        <!-- <image
          src="../../static/jifen_icon.png"
          mode=""
          class="main_price_img"
        ></image> -->
        总金额</view
      >
      <view class="main_num"
        >￥{{ shopDetail.lock_balance ? shopDetail.lock_balance : 0 }}</view
      >

      <!-- <view class="main_notice">-累计获得积分-</view> -->
      <view class="main_notice"></view>

      <view class="main_line"></view>

      <view class="main_bottom">
        <view class="main_item" @click="handleSort(0)">
          <view
            class="main_item_text"
            :class="now_check == 0 ? 'main_item_active' : ''"
            >全部</view
          >
        </view>

        <view class="main_item" @click="handleSort(1)">
          <view
            class="main_item_text"
            :class="now_check == 1 ? 'main_item_active' : ''"
            >收入</view
          >
        </view>

        <view class="main_item" @click="handleSort(2)">
          <view
            class="main_item_text"
            :class="now_check == 2 ? 'main_item_active' : ''"
            >支出</view
          >
        </view>
      </view>
    </view>

    <view class="information_wrapper">
      <view class="information" v-for="(item, index) in list">
        <view class="information_left">
          <view class="information_left_row1">{{ item.remark }}</view>
          <view class="information_left_row2">{{ item.created_at }}</view>
        </view>
        <view class="information_right">
          <text v-if="Number(item.after_balance) > Number(item.before_balance)"
            >+</text
          >
          <text v-else>-</text>
          <text>￥{{ item.money }}</text>
        </view>
      </view>
    </view>

    <view class="transfer_button" @click="toWithdrawal">
      提现到亿数伽
    </view>

    <u-popup
      v-model="show_transaction"
      mode="center"
      width="490rpx"
      height="290rpx"
      :border-radius="24"
      :closeable="true"
      :mask-close-able="false"
      @close="operation_password = null;Withdrawal_price = null"
    >
      <view class="Transaction_eject" style="z-index: 999;">
        <text class="Transaction_top">输入交易密码</text>
        <input
          type="password"
          value=""
          class="Transaction_center"
          v-model="operation_password"
        />
        <text class="Transaction_bottom" @click="transactionComfirm">确定</text>
      </view>
    </u-popup>

    <u-popup
      v-model="show_Withdrawal"
      mode="center"
      width="490rpx"
      height="290rpx"
      :border-radius="24"
      :closeable="true"
      :mask-close-able="false"
    >
      <view class="Transaction_eject">
        <text class="Transaction_top">输入提现金额</text>
        <view class="input_box">
          <span>￥</span>
          <input
          type="number"
          value=""
          class="Transaction_center"
          v-model="Withdrawal_price"
        />
        </view>
        <text class="Transaction_bottom" @click="transactionComfirm">确定</text>
      </view>
    </u-popup>

    <empty :show.sync="list.length == 0 && is_done"></empty>
  </view>
</template>

<script>
import api from "@/api/api.js";
import tip from "@/utils/tip.js";
import empty from "@/components/empty/empty";
export default {
  components: {
    empty,
  },
  data() {
    return {
      price: "",
      walllestext: null,
      list: [],
      walletDetail: null,
      page: 1,
      now_check: 0,
      is_done: false,
      shopDetail: {},

      show_transaction:false,
      show_Withdrawal:false,
      Withdrawal_price:null,
      operation_password:null
    };
  },
  onLoad(options) {},
  onShow() {
    this.getuserWallet();
    this.record(true);
  },
  // 页面的触底事件
  onReachBottom() {
    this.page++;
    this.$u.throttle(this.record(), 1000, true);
  },
  methods: {
    async transactionComfirm(){
      if(!this.Withdrawal_price && this.show_Withdrawal) return tip.defaults('请输入提现金额');
      if (this.Withdrawal_price <= 0) return  tip.defaults("提现金额必须大于0");
      if(!this.operation_password && this.show_Withdrawal) {
        this.show_Withdrawal = false
        this.show_transaction = true
        return
      }
      if(!this.operation_password && this.show_transaction) return tip.defaults('请输入交易密码');
      let res = await api.lockBalanceToYsj({
        query: {
          lock_balance: this.Withdrawal_price,
          operation_password: this.operation_password,
        },
        loading: "加载中",
        method: "post",
      });
      if(res.code == 0){
        this.getuserWallet();
        this.record(true);
        this.show_transaction = false
        tip.defaults('提现成功');
      }else{
        tip.defaults(res.msg);
      }
    },
    toWithdrawal(){
      this.show_Withdrawal = true
    },
    toTransfer() {
      uni.navigateTo({
        url: `../coinWallet/coinWallet_transfer`,
      });
    },
    handleBack() {
      uni.navigateBack({
        delta: 1,
      });
    },
    async getuserWallet() {
      let res = await api.userWallet({
        method: "get",
        query: {},
        loading: "加载中",
      });

      if (res.code === 0) {
        this.shopDetail = res.data;
        console.log("----this.shopDetail", this.shopDetail);
      } else {
        tip.defaults(res.msg);
      }
    },

    handleSort(index) {
      this.now_check = index;
      if (index == 0) {
        this.record(true);
      } else if (index == 1) {
        this.record(true);
      } else if (index == 2) {
        this.record(true);
      }
    },

    async record(refresh) {
      if (refresh) {
        this.page = 1;
      }

      let res = await api.incomeDetails({
        query: {
          page: this.page,
          is_pay_out: this.now_check == 0 ? "" : this.now_check - 1,
          type: "",
          wallet_type: 2,
        },
        method: "POST",
        loading: "加载中",
      });

      if (res.code == 0) {
        this.is_done = true;
        uni.stopPullDownRefresh();

        if (refresh) {
          this.list = res.data;
        } else {
          this.list = [...this.list, ...res.data];
        }
      } else {
        tip.defaults(res.msg);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
@import "../../style/yuanchuang.scss";
.content {
  font-family: PingFangSC-Regular, PingFang SC;
  padding: 0 30rpx 100rpx 30rpx;
  background: $bg-color1;

  min-height: 100vh;
}
.status_bar {
  margin: 0 -30rpx;
  height: var(--status-bar-height);
  width: 750rpx;
}
.main {
  margin: 0 -30rpx;
  padding: 0 30rpx;
  height: 412rpx;
  background-image: url(../../static/integral_bg.png);
  background-repeat: no-repeat;
  background-size: 100%;
  &_top {
    margin-left: -30rpx;
    position: relative;
    // display: flex;

    width: 750rpx;
    height: 88rpx;
    text-align: center;
    &_img {
      position: absolute;
      left: 30rpx;
      top: 23rpx;
      width: 42rpx;
      height: 42rpx;
    }
    &_text {
      margin: 0 auto;
      // width: 68rpx;
      height: 88rpx;
      font-size: 34rpx;
      font-weight: 500;
      color: #ffffff;
      line-height: 88rpx;
    }
    &_right {
      position: absolute;
      top: 24rpx;
      right: 30rpx;
      // width: 112rpx;
      height: 40rpx;
      font-size: 28rpx;
      font-weight: 400;
      color: #ffffff;
      line-height: 40rpx;
    }
  }
  &_price {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 30rpx auto 0;
    // width: 128rpx;
    height: 44rpx;
    font-size: 32rx;
    font-weight: 400;
    color: #ffffff;
    line-height: 44rpx;
    text-align: center;
    &_img {
      margin-right: 14rpx;
      width: 32rpx;
      height: 32rpx;
    }
  }
  &_num {
    margin-top: 14rpx;
    // width: 204rpx;
    height: 86rpx;
    // font-size: 44rpx;
    font-size: 72rpx;
    font-weight: bold;
    color: #ffffff;
    line-height: 86rpx;
    text-align: center;
  }
  &_notice {
    margin-top: 10rpx;
    // width: 174rpx;
    height: 34rpx;
    font-size: 24rpx;
    font-weight: 400;
    color: #ffffff;
    line-height: 34rpx;
    text-align: center;
  }
  &_line {
    margin-top: 40rpx;
    width: 750rpx;
    height: 2rpx;
    background: #d8d8d8;
    opacity: 0.18;
  }
  &_bottom {
    // padding: 28rpx 0 0 0;
    margin: 0 -30rpx;
    height: 104rpx;
    // padding: 24rpx 2rpx 0 2rpx;
    padding: 0 2rpx 0 2rpx;
    display: flex;
    align-items: center;
    background: #292b2b;
  }
  &_item {
    // padding: 0 48rpx;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    // text-align: center;
    &_img {
      width: 32rpx;
      height: 32rpx;
    }
    &_text {
      margin-left: 6rpx;
      // width: 56rpx;
      height: 40rpx;
      font-size: 28rpx;
      font-weight: 400;
      color: #cccccc;
      line-height: 40rpx;
    }
    &_active {
      color: $text-color3;
    }
  }
  &_item:not(:first-child) {
    border-left: 2rpx solid #404040;
  }
}
.title {
  height: 40rpx;
  font-size: 28rpx;
  font-weight: 400;
  color: #0c1125;
  line-height: 40rpx;
}
.record {
  margin-top: 30rpx;
  display: flex;
  align-items: center;
  width: 690rpx;
  height: 242rpx;
  border-radius: 24rpx;
  background-image: url(../../static/wallet_background.png);
  background-repeat: no-repeat;
  background-size: 100% 242rpx;
  display: flex;
  justify-content: space-between;
  position: relative;
  .record_price {
    display: flex;
    flex-direction: column;
    margin: 30rpx;
    text {
      color: #ffffff;
      font-size: 16px;
      margin: 10rpx 0;
    }
    .record_price_text {
      margin: 10rpx 0;
      text:nth-child(2) {
        color: #ffffff;
        font-size: 24px;
        font-weight: bold;
      }
    }
  }
  .record_button {
    position: absolute;
    bottom: 30rpx;
    right: 15rpx;
    color: #ffffff;
    text {
      margin: 0 15rpx;
      border: 2rpx solid #ffffff;
      border-radius: 32rpx;
      padding: 8rpx 16rpx;
    }
  }
}
.price {
  margin-top: 30rpx;
  width: 100%;
  background: $bg-color3;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text {
    margin: 30rpx;
    color: $text-color1;
  }
  text:first-child {
    font-size: 16px;
  }
  text:nth-child(2) {
    font-size: 12px;
  }
  .price_input {
    height: 100rpx;
    display: flex;
    align-content: flex-start;
    input {
      height: 120rpx;
      line-height: 120rpx;
      color: $text-color1;
    }
    border-bottom: 2rpx solid #313535;
    text {
      font-size: 22px;
      font-weight: 500;
    }
  }
}
.listwhole {
  display: flex;
  align-content: center;
  justify-content: space-between;
  margin: 30rpx 0;
  padding: 30rpx;
  border-radius: 24rpx;
  background-color: $bg-color3;
  height: 150rpx;
  .list_new {
    color: $text-color1;
    margin: auto;
    .list_new_img {
      width: 24rpx;
      height: 24rpx;
      margin-right: 10rpx;
    }
  }
  .list_left {
    display: flex;
    .list_left_img {
      width: 80rpx;
      height: 80rpx;
    }
    .list_left_right {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      margin-left: 30rpx;
      color: $text-color1;
      font-size: 28rpx;
    }
  }
  .list_right_img {
    margin: auto 0;
    width: 30rpx;
    height: 30rpx;
    // margin-top: 15rpx;
  }
}

.button {
  margin-top: 50rpx;
  width: 690rpx;
  height: 90rpx;
  color: #ffffff;
  background: $button;
  background-repeat: no-repeat;
  // background-attachment: fixed;
  background-size: 100% 100%;
  border-radius: 16rpx;

  font-size: 32rpx;
  font-weight: 400;
  line-height: 90rpx;
  text-align: center;
}
.detail {
  margin-top: 70rpx;
  &_title {
    font-size: 30rpx;
    font-weight: 400;
    color: #ffffff;
    line-height: 40rpx;
    margin: 30rpx 0;
  }
  &_row {
    margin-top: 30rpx;
    font-size: 28rpx;
    font-weight: 400;
    color: #bbbbbe;
    line-height: 40rpx;
    white-space: break-spaces;
  }
  &_row + &_row {
    margin-top: 20rpx;
  }
}
.input_center {
  color: #ffffff;
  // height: 260rpx;
  // padding: 30rpx 0 0rpx;
  word-break: break-all;
  margin: 30rpx;
  max-height: 300rpx;
}
.Transaction_eject {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  height: 290rpx;
  background-color: $bg-color1;
  .Transaction_top {
    margin-top: 50rpx;
    font-size: 32rpx;
    color: $text-color1;
  }
  .Transaction_center {
    padding: 0 20rpx;
    border: 2rpx solid #262934;
    background: $bg-color3;
    border-radius: 16rpx;
    height: 85rpx;
    width: 80%;
    color: #ffffff;
  }
  .Transaction_bottom {
    font-size: 32rpx;
    color: $text-color1;
    margin-bottom: 30rpx;
  }
  .input_box{
    background-color: #292B2B;
    border-radius: 16rpx;
    padding: 0 10rpx;
    display: flex;
    span {
      color: #ffffff;
      font-weight: 500;
      font-size: 44rpx;
      line-height:85rpx ;
    }
  }
}
.pricemode {
  color: $text-color1;
  background-color: $bg-color3;
  display: flex;
  justify-content: space-between;
  padding: 30rpx;
  margin-top: 30rpx;
  image {
    margin: auto 0;
    width: 30rpx;
    height: 30rpx;
  }
  border-radius: 24rpx;
  font-size: 28rpx;
}
.information_wrapper {
  margin-top: 30rpx;
}
.information {
  padding: 30rpx 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2rpx solid #292b2b;
  &_left {
    &_row1 {
      // width: 192rpx;
      height: 44rpx;
      font-size: 32rpx;
      font-weight: 500;
      color: #ffffff;
      line-height: 44rpx;
    }
    &_row2 {
      margin-top: 8rpx;
      width: 242rpx;
      height: 34rpx;
      font-size: 24rpx;
      font-weight: 400;
      color: #999999;
      line-height: 34rpx;
    }
  }
  &_right {
    // width: 64rpx;
    height: 42rpx;
    font-size: 36rpx;
    font-weight: 600;
    color: #ffffff;
    line-height: 42rpx;
  }
}
// .information + .information {

// }
.fixed {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;

  width: 750rpx;
  height: 130rpx;
  background: #292b2b;
  &_button {
    width: 670rpx;
    height: 90rpx;
    margin: 20rpx auto 0;
    background: $button;
    background-repeat: no-repeat;
    background-size: 100%;

    font-size: 32rpx;
    font-weight: 400;
    color: #ffffff;
    line-height: 90rpx;
    text-align: center;
  }
}
.transfer_button{
  position: fixed;
  bottom: 90rpx;
  left: 40rpx;
  right: 40rpx;
  height: 90rpx;
  background: linear-gradient(90deg, #1FE6E6 0%, #3F9ED2 48%, #DF7FD6 100%);
  text-align: center;
  line-height: 90rpx;
  border-radius: 60rpx 5rpx 60rpx 5rpx;
  color: #ffffff;
  font-size: 32rpx;
}
</style>